//
//  NewFeatureCell.swift
//  XinLangWeibo10
//
//  Created by 白利兵 on 15/10/19.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit
import SnapKit
class NewFeatureCell: UICollectionViewCell {
    // 懒加载图片框
    lazy var imageView: UIImageView = UIImageView()
    // 懒加载按钮
    lazy var startButton: UIButton = UIButton(title: "进入首页", fontSize: 17.0, color: UIColor.whiteColor(), backImageName: "new_feature_finish_button", backColor: UIColor.clearColor())
    // 构造函数
    override init(frame: CGRect) {
        let frame = UIScreen.mainScreen().bounds
        super.init(frame: frame)
        // 设置UI
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // 设置UI
    func setUI() {
        addSubview(imageView)
        addSubview(startButton)
        imageView.frame = bounds
        startButton.hidden = true
        // 设置约束
        startButton.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp_centerX)
            make.bottom.equalTo(self.snp_bottom).offset(-200)
        // 注册点击事件
        startButton.addTarget(self, action: "entryMainView", forControlEvents: UIControlEvents.TouchUpInside)
        }
    }
    
    @objc private func entryMainView() {
        // 发送通知
        print("开始体验")
        NSNotificationCenter.defaultCenter().postNotificationName(WBNotificationSwithRootView, object: nil)
    }
    func startAnima() {
        // 显示按钮
        startButton.hidden = false
        startButton.transform = CGAffineTransformMakeScale(0, 0)
        // 禁止交互
        startButton.userInteractionEnabled = false
        UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 10, options: [], animations: { () -> Void in
            self.startButton.transform = CGAffineTransformIdentity
            }) { (Bool) -> Void in
            self.startButton.userInteractionEnabled = true
        }
    }
    
}







